package util;

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class DateTimeUtils {

	public static final DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");

	public static final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

	public static String dPlusMonths(String startDate,long n){
		LocalDate time = LocalDate.parse(startDate, df);
		return time.plusMonths(n).format(df);
	}

	public static String dtPlusMonths(String startDate,long n){
		LocalDateTime time = LocalDateTime.parse(startDate, dtf);
		return time.plusMonths(n).format(dtf);
	}
	
	public static long diffHours(String startTime,String endTime){
		LocalDateTime stime = LocalDateTime.parse(startTime, dtf);
		LocalDateTime etime = LocalDateTime.parse(endTime, dtf);
		Duration duration = Duration.between(stime,etime);
		return duration.toHours();
	}
	
	public static long diffMinutes(String startTime,String endTime){
		LocalDateTime stime = LocalDateTime.parse(startTime, dtf);
		LocalDateTime etime = LocalDateTime.parse(endTime, dtf);
		Duration duration = Duration.between(stime,etime);
		return duration.toMinutes();
	}

	public static String dtNow(){
		return LocalDateTime.now().format(dtf);		
	}
	
	public static String dNow(){
		return LocalDateTime.now().format(df);
	}

}
